//
//  LiveHomeViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/11.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "LiveHomeViewController.h"
#import "LivingGoodsViewController.h"
#import "LiveAllTypeViewController.h"
#import "SDCycleScrollView.h"
#import "LiveHomeModel.h"
#import "BannerModel.h"
#import "ProdTypeModel.h"
#import "ProductModel.h"
#import "ImagelistModel.h"
#import "LiveGoodsDetailViewController.h"
#import "LiveSearchViewController.h"

static NSString *cellPath = @"LiveHomeCell";
static NSString * CellIdentifier = @"LiveHomeCell";
@interface LiveHomeViewController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)UICollectionView *collectionView;
@property (nonatomic, strong)SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong)UIView *navView;
@property (nonatomic, strong)LiveHomeModel *liveModel;

@end

@implementation LiveHomeViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    _navView.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _navView.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatUI];
    [self requestLifeHomePage];

}

- (void)creatUI
{
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.translucent = NO;
    self.navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, STA_NAV_HEIGHT)];
    _navView.backgroundColor = [UIColor whiteColor];
    [self.navigationController.view addSubview:_navView];
    UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(20, STA_NAV_HEIGHT-35, SCREEN_WIDTH-40, 30)];
    grayView.backgroundColor = LinesColor;
    grayView.layer.cornerRadius = 15;
    grayView.layer.masksToBounds = YES;
    [_navView addSubview:grayView];
    UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(10, 5, 20, 20) ImageName:@"shouyess"];
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    [grayView addSubview:imgView];
    UILabel *pladerLab = [ZCControl createLabelWithFrame:CGRectMake(40, 0, SCREEN_WIDTH-120, 30) Font:12.0 Text:@"输入您要搜索的内容" Color:BlaTiColor];
    pladerLab.textAlignment = NSTextAlignmentCenter;
    [grayView addSubview:pladerLab];
    UIButton *searchBtn = [ZCControl createButtonWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-40, 30) ImageName:nil Target:self Action:@selector(searchBtnAction) Title:nil Font:14.0];
    searchBtn.backgroundColor = [UIColor clearColor];
    [grayView addSubview:searchBtn];
    
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-SCREER_HeiX-TABBAR_HEIGHT) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewHeaderData)];
    self.tableview.estimatedRowHeight = 0;
    self.tableview.estimatedSectionHeaderHeight = 0;
    self.tableview.estimatedSectionFooterHeight = 0;
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*displaywidth)];
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*displaywidth) delegate:self placeholderImage:nil];
    _cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    _cycleScrollView.delegate = self;
    //是否自动轮播
    _cycleScrollView.autoScroll = YES;//是否自动轮播 bannerImageViewContentMode
    //图片样式
    _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleScrollView.clipsToBounds = YES;
    _cycleScrollView.currentPageDotColor = ThemeColor;
    _cycleScrollView.pageDotColor = [UIColor whiteColor];
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
    [headerView addSubview:_cycleScrollView];
    self.tableview.tableHeaderView = headerView;
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100) collectionViewLayout:layout];
    _collectionView.backgroundColor = BacksColor;
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.scrollEnabled = NO;
    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier];
    
}



- (void)loadNewHeaderData
{
    [self requestLifeHomePage];
}

//搜索
- (void)searchBtnAction
{
    LiveSearchViewController *vc = [[LiveSearchViewController alloc] init];
    vc.areaId = @"3";
    [self.navigationController pushViewController:vc animated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 2;
    }
    if (section == 1)
    {
        if (_liveModel)
        {
            NSArray *producAry = _liveModel.productList;
            if (producAry.count > 3)
            {
                return 4;
            }
            return producAry.count+1;
        }
        return 0;
    }
    else
    {
        if (_liveModel)
        {
            NSArray *producAry = _liveModel.productList;
            if (producAry.count > 3)
            {
                return 1;
            }
            return 0;
        }
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (_liveModel)
    {
        if (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                NSArray *typeAry = _liveModel.productTypeList;
                NSInteger num = typeAry.count;
                if (typeAry.count > 10)
                {
                    num = 10;
                }
                CGFloat W = SCREEN_WIDTH/5;
                for (int i = 0; i < num; i++)
                {
                    ProdTypeModel *typeModel = typeAry[i];
                    UIImageView *imageview = [ZCControl createImageViewWithFrame:CGRectMake((W-40*displaywidth)/2+W*(i%5), 10*displaywidth+(i/5)*80*displaywidth, 40*displaywidth, 40*displaywidth) ImageName:@""];
                    NSString *nameStr = typeModel.typeName;
                    if (typeAry.count > 10 && i == 9)
                    {
                        imageview.image = [UIImage imageNamed:@"quanb"];
                        nameStr = @"全部";
                    }
                    else
                    { 
                        [imageview sd_setImageWithURL:[NSURL URLWithString:typeModel.imgUrl]];
                    }
                    imageview.contentMode = UIViewContentModeScaleAspectFit;
                    imageview.layer.cornerRadius = 20*displaywidth;
                    imageview.layer.masksToBounds = YES;
                    [cell.contentView addSubview:imageview];
                    UILabel *nameLab = [ZCControl createLabelWithFrame:CGRectMake(W*(i%5), 50*displayheight+(i/5)*80*displaywidth, W, 30*displaywidth) Font:12.0 Text:nameStr Color:RGB(77, 77, 77)];
                    nameLab.textAlignment = NSTextAlignmentCenter;
                    [cell.contentView addSubview:nameLab];
                    UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(W*(i%5), 80*displaywidth*(i/5), W, 79*displayheight) ImageName:nil Target:self Action:@selector(closeProdTypeAction:) Title:nil Font:12.0];
                    btn.backgroundColor = [UIColor clearColor];
                    btn.tag = 100+i;
                    [cell.contentView addSubview:btn];
                    
                }
                UIView *lineAview = [[UIView alloc] initWithFrame:CGRectMake(0, 159*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineAview.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineAview];
                
            }
            else
            {
                NSArray *squareAry = _liveModel.squareAD;
                NSInteger squNum = squareAry.count;
                if (squareAry.count > 2)
                {
                    squNum = 2;
                }
                CGFloat squaW = SCREEN_WIDTH/2-15*displaywidth;
                for (int i = 0; i < squNum; i++)
                {
                    BannerModel *squaModel = squareAry[i];
                    UIImageView *imageview = [ZCControl createImageViewWithFrame:CGRectMake(10*displaywidth+(squaW+10*displaywidth)*i, 10*displaywidth, squaW, 120*displaywidth) ImageName:@""];
                    [imageview sd_setImageWithURL:[NSURL URLWithString:squaModel.imgUrl]];
                    imageview.contentMode = UIViewContentModeScaleAspectFill;
                    imageview.layer.masksToBounds = YES;
                    [cell.contentView addSubview:imageview];
                }
                UIView *lineBview = [[UIView alloc] initWithFrame:CGRectMake(0, 139*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineBview.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineBview];
            }
        }
        else if (indexPath.section == 1)
        {
            UIView *lineCview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1*displaywidth)];
            lineCview.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineCview];
            NSArray *producAry = _liveModel.productList;
            NSInteger proNum = 0;
            if (producAry.count > 3)
            {
                proNum = 4;
            }
            else
            {
                proNum = producAry.count + 1;
            }
            if (indexPath.row == proNum-1)
            {
                NSArray *horiAry = _liveModel.horizontalAD;
                if (horiAry.count > 0)
                {
                    BannerModel *horiModel = horiAry[0];
                    UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(0, 6*displaywidth, SCREEN_WIDTH, 124*displaywidth) ImageName:@""];
                    [imgView sd_setImageWithURL:[NSURL URLWithString:horiModel.imgUrl]];
                    imgView.contentMode = UIViewContentModeScaleAspectFill;
                    imgView.layer.masksToBounds = YES;
                    [cell.contentView addSubview:imgView];
                }
                UIView *lineDview = [[UIView alloc] initWithFrame:CGRectMake(0, 134*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineDview.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineDview];
                UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 135*displaywidth, 160*displaywidth, 29*displaywidth) Font:13.0 Text:@"推荐商品" Color:RGB(77, 77, 77)];
                [cell.contentView addSubview:titLab];
                UIView *lineEview = [[UIView alloc] initWithFrame:CGRectMake(0, 164*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineEview.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineEview];
            }
            else
            {
                ProductModel *productModel = producAry[indexPath.row];
                NSArray *imgArray = productModel.productImgList;
                UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, 80*displaywidth, 80*displaywidth) ImageName:@""];
                if (imgArray.count > 0)
                {
                    ImagelistModel *imgModel = imgArray[0];
                    [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
                }
                imgView.contentMode = UIViewContentModeScaleAspectFill;
                imgView.layer.masksToBounds = YES;
                [cell.contentView addSubview:imgView];
                UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 5*displaywidth, SCREEN_WIDTH-130*displaywidth, 35*displaywidth) Font:12.0 Text:productModel.productName Color:RGB(77, 77, 77)];
                titlab.lineBreakMode = NSLineBreakByTruncatingTail;
                titlab.adjustsFontSizeToFitWidth = NO;
                [cell.contentView addSubview:titlab];

                UILabel *moneyLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 70*displaywidth, 100*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"%@ +",productModel.priceDescribe] Color:RGB(241, 90, 36)];
                CGRect abounds = [moneyLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-200*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)} context:nil];
                CGFloat width1 = abounds.size.width+20;
                moneyLab.frame = CGRectMake(115*displaywidth, 70*displaywidth, width1, 20*displaywidth);
                [cell.contentView addSubview:moneyLab];
                
                UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(width1+120*displaywidth, 70*displaywidth, 120*displaywidth, 20*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",productModel.integral] Color:[UIColor whiteColor]];
                integralLab.textAlignment = NSTextAlignmentCenter;
                integralLab.layer.cornerRadius = 2;
                integralLab.layer.masksToBounds = YES;
                integralLab.backgroundColor = RGB(24, 159, 186);
                [cell.contentView addSubview:integralLab];
                CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
                CGFloat width2 = bounds1.size.width+10;
                if (bounds1.size.width > 120*displaywidth)
                {
                    width2 = 120*displaywidth;
                }
                integralLab.frame = CGRectMake(width1+120*displaywidth, 70*displaywidth, width2, 20*displaywidth);
                
                UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(width1+width2+140*displaywidth, 70*displaywidth, 100*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@" %@购买",productModel.productSales] Color:RGB(179, 179, 179)];
                [cell.contentView addSubview:numLab];
                
                UIView *lineFView = [[UIView alloc] initWithFrame:CGRectMake(0, 99*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
                lineFView.backgroundColor = LinesColor;
                [cell.contentView addSubview:lineFView];
            }
            
        }
        else
        {
            NSArray *producAry = _liveModel.productList;
            cell.backgroundColor = BacksColor;
            if (producAry.count > 3)
            {
                NSInteger proNum = producAry.count-3;
                NSInteger K = proNum/2;
                if (proNum % 2 != 0)
                {
                    K+=1;
                }
                [_collectionView removeFromSuperview];
                _collectionView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 245*displaywidth*K);
                [cell.contentView addSubview:_collectionView];
            }
        }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        NSArray *producAry = _liveModel.productList;
        NSInteger numCount = 0;
        if (producAry.count > 3)
        {
            numCount = 4;
        }
        else
        {
            numCount = producAry.count + 1;
        }
        if (indexPath.row != numCount-1)
        {
            ProductModel *productModel = producAry[indexPath.row];
            LiveGoodsDetailViewController *vc = [[LiveGoodsDetailViewController alloc] init];
            vc.idStr = s_str(productModel.ID);
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        if (indexPath.row == 0)
        {
            if (_liveModel)
            {
                NSArray *typeAry = _liveModel.productTypeList;
                if (typeAry.count > 5)
                {
                    return 160*displaywidth;
                }
                return 80*displaywidth;
            }
            return 160*displaywidth;
        }
        return 140*displaywidth;
    }
    else if (indexPath.section == 1)
    {
        if (_liveModel)
        {
            NSArray *producAry = _liveModel.productList;
            NSInteger proNum = 0;
            if (producAry.count > 3)
            {
                proNum = 4;
            }
            else
            {
                proNum = producAry.count + 1;
            }
            if (indexPath.row == proNum-1)
            {
                return 165*displaywidth;
            }
            return 100*displaywidth;
        }
        return 100*displaywidth;
    }
    else
    {
        NSArray *producAry = _liveModel.productList;
        if (producAry.count > 3)
        {
            NSInteger proNum = producAry.count-3;
            NSInteger K = proNum/2;
            if (proNum % 2 != 0)
            {
                K+=1;
            }
            return 245*displaywidth*K;
        }
        return 0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1)
    {
        return 30*displaywidth;
    }
    return 0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *myView = [[UIView alloc] init];
    myView.backgroundColor = [UIColor whiteColor];
    if (section == 1)
    {
        myView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 30*displaywidth);
        UILabel *titleLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0*displaywidth, 160*displaywidth, 30*displaywidth) Font:13.0 Text:@"推荐商品" Color:RGB(77, 77, 77)];
        [myView addSubview:titleLab];
    }
    return myView;
}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    NSArray *producAry = _liveModel.productList;
    if (producAry.count > 3)
    {
        NSInteger proNum = producAry.count-3;
        return proNum;
    }
    return 0;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    for (id subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    CGFloat W = SCREEN_WIDTH/2;
    CGFloat X = 0;
    if (indexPath.row %2 == 1)
    {
        X = 7.5*displaywidth;
    }
    NSArray *producAry = _liveModel.productList;
    cell.backgroundColor = BacksColor;
    if (producAry.count > 3)
    {
        ProductModel *productModel = producAry[indexPath.row+3];
        NSArray *imgArray = productModel.productImgList;
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(X, 0, W-7.5*displaywidth, 240*displaywidth)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [cell.contentView addSubview:whiteView];
        UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, W-7.5*displaywidth, 170*displaywidth)];
        if (imgArray.count > 0)
        {
            ImagelistModel *imgModel = imgArray[0];
            [imageView1 sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
        }
        imageView1.contentMode = UIViewContentModeScaleAspectFill;
        imageView1.layer.masksToBounds = YES;
        [whiteView addSubview:imageView1];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 170*displaywidth, W-37.5*displaywidth, 25*displaywidth) Font:12.0 Text:productModel.productName Color:RGB(77, 77, 77)];
        titlab.lineBreakMode = NSLineBreakByTruncatingTail;
        titlab.adjustsFontSizeToFitWidth = NO;
        [cell.contentView addSubview:titlab];

        UILabel *priceLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 195*displaywidth, W-37.5*displaywidth, 15*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@"￥%.1lf元 +",[productModel.price floatValue]] Color:priceColor];
        [cell.contentView addSubview:priceLab];
        UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 212.5*displaywidth, (W-37.5*displaywidth)/2, 15*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",productModel.integral] Color:[UIColor whiteColor]];
        integralLab.textAlignment = NSTextAlignmentCenter;
        integralLab.layer.cornerRadius = 2;
        integralLab.layer.masksToBounds = YES;
        integralLab.backgroundColor = RGB(24, 159, 186);
        [cell.contentView addSubview:integralLab];
        CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(W-37.5*displaywidth, 15*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
        CGFloat width1 = bounds1.size.width+10;
        if (bounds1.size.width > (W-37.5*displaywidth)/2)
        {
            width1 = (W-37.5*displaywidth)/2;
        }
        integralLab.frame = CGRectMake(15*displaywidth, 212.5*displaywidth, width1, 15*displaywidth);
        UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth, 210*displaywidth, 80*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@" %@购买",productModel.productSales] Color:RGB(179, 179, 179)];
        [cell.contentView addSubview:numLab];
       
    }
   
    return cell;
}

//定义每一个cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(SCREEN_WIDTH/2, 245*displaywidth);
}

//cell的点击事件
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //cell被电击后移动的动画
    [collectionView selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionTop];
    if (_liveModel)
    {
        NSArray *producAry = _liveModel.productList;
        if (producAry.count > 3)
        {
            ProductModel *productModel = producAry[indexPath.row+3];
            LiveGoodsDetailViewController *vc = [[LiveGoodsDetailViewController alloc] init];
            vc.idStr = s_str(productModel.ID);
            [self.navigationController pushViewController:vc animated:YES];
        }
       
    }

    
   
}






- (void)closeProdTypeAction:(UIButton *)btn
{
    NSArray *typeAry = _liveModel.productTypeList;
    ProdTypeModel *model = typeAry[btn.tag-100];
    if (typeAry.count > 10 && btn.tag == 109)
    {
        LiveAllTypeViewController *vc = [[LiveAllTypeViewController alloc] init];
        vc.allTypeAry = typeAry;
        [self.navigationController pushViewController:vc animated:YES];
    }
    else
    {
        LivingGoodsViewController *vc = [[LivingGoodsViewController alloc] init];
        vc.typeID = s_str(model.ID);
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)requestLifeHomePage
{
    WEAKSELF;
    [HYBaseHandler requestLifeHomePageParmers:nil Success:^(id obj) {
        [weakSelf.tableview.mj_header endRefreshing];
        if ([obj server_Getcodecheck])
        {
            weakSelf.liveModel = [LiveHomeModel mj_objectWithKeyValues:obj[@"data"]];
            dispatch_async(dispatch_get_main_queue(), ^{
                NSArray *bannerAry = weakSelf.liveModel.bannerList;
                NSMutableArray *imgAry = [NSMutableArray arrayWithCapacity:0];
                for (BannerModel *model in bannerAry)
                {
                    [imgAry addObject:model.imgUrl];
                }
                weakSelf.cycleScrollView.imageURLStringsGroup = imgAry;
                [weakSelf.tableview reloadData];
                [weakSelf.collectionView reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        [weakSelf.tableview.mj_header endRefreshing];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
